/**
* @description: 951. 翻转等价二叉树
* @author hewei
* @date 2022/9/22 16:44
* @version 1.0
*/

public class FlipEquiv {

    public boolean flipEquiv(TreeNode root1, TreeNode root2) {
        if ((root1 == null && root2 != null) || (root1 != null && root2 == null)) return false;
        if (root1 == null) return true;
        if (root1.val != root2.val) return false;
        return (flipEquiv(root1.left, root2.left) && flipEquiv(root1.right, root2.right))
                || (flipEquiv(root1.left, root2.right) && flipEquiv(root1.right, root2.left));
    }
}
